package com.apartment.common.utils.uuid;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class EnumUtils {

    public static final String INDEX = "getId";
    public static final String VALUE= "getName";
    public static final String SECLET= "getSelect";

    /**
     * des.
     * @author       : RazaJin
     * @param        : index 为枚举下标   value为枚举的对应值  这个参数需要传对应的get方法名称
     * @return       :
     * @date         : 2020/8/31 0031 上午 10:56
     */
    public static List<HashMap<String,Object>> iterEnum(String enumName,String index,String value,String select){

        List<HashMap<String,Object>> list = new ArrayList<>();
        try {
            Class<?> clzz = Class.forName(enumName);
            // 获取所有常量
            Object[] objects = clzz.getEnumConstants();
            //获取指定方法
            Method coinId = clzz.getMethod(index);
            Method coinValue = clzz.getMethod(value);
            Method coinSelect = clzz.getMethod(select);
            for (Object object : objects) {
                HashMap<String, Object> stringObjectHashMap = new HashMap<>();
                stringObjectHashMap.put(coinId.getName(),coinId.invoke(object));
                stringObjectHashMap.put(coinValue.getName(),coinValue.invoke(object));
                stringObjectHashMap.put(coinSelect.getName(),coinSelect.invoke(object));
                list.add(stringObjectHashMap);
            }
        } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
        }
        return list;
    }
}
